home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_9.zip / INIT.C < prev    next >
C/C++ Source or Header  |  1993-07-27  |  12KB  |  434 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. #ifdef MONITOR
  10. char MON_PACKAGE_NAME[33] = "";
  11. #endif
  12.  
  13. #define GEN
  14.  
  15. #include "hdr.h"
  16. #include "vars.h"
  17. #include "gvars.h"
  18. #include "libhdr.h"
  19. #include "segment.h"
  20. #include "slot.h"
  21. #include "ifile.h"
  22. #include "readp.h"
  23. #include "setp.h"
  24. #include "genp.h"
  25. #include "miscp.h"
  26. #include "smiscp.h"
  27. #include "arithp.h"
  28. #include "axqrp.h"
  29. #include "initp.h"
  30.  
  31. static Tuple precedes_map_new();
  32. static void init_predef_exceptions();
  33. static void init_predef_exception(int, int, int, char *);
  34.  
  35. /* These are defined here since type Segment not known in gvars.[ch] */
  36. Segment    CODE_SEGMENT, DATA_SEGMENT, DATA_SEGMENT_MAIN;
  37. Segment FIELD_TABLE, VARIANT_TABLE;
  38. Tuple units_in_compilation;
  39.  
  40. /* INITALIZATIONS AND FINALIZATION
  41.  * General initialization
  42.  */
  43.  
  44. void initialize_1()                                            /*;initialize_1*/
  45. {
  46.     /*
  47.      * Initializes global variables that are to be kept between the two
  48.      * phases of generation.
  49.      */
  50.  
  51.     int    i;
  52.  
  53.     /* initialize FIELD_TABLE and VARIANT_TABLE. These are data segments
  54.      * that are reset to be empty but are not reallocated for each unit
  55.      */
  56.     FIELD_TABLE = segment_new(SEGMENT_KIND_DATA, 0);
  57.     VARIANT_TABLE = segment_new(SEGMENT_KIND_DATA, 0);
  58.     /* tree maps */
  59.     ivalue_1 = int_fri(1); 
  60.     ivalue_10 = int_fri(10);
  61.     int_const_0 = int_const(0);
  62.     rat_value_10 = rat_fri(ivalue_1, ivalue_10);
  63.  
  64.     int_const_null_task = int_const(-1);
  65.  
  66.     /*initializations of variables used only by generator */
  67.     /* explicit_ref_0 is used to pass addresses to be filled in later, and
  68.      * corresponds to [0, 0] case in SETL version.
  69.      */
  70.     explicit_ref_0 = explicit_ref_new(0, 0);
  71.     global_reference_tuple = tup_new(0);
  72.  
  73.     N_SIDE(OPT_NODE) = FALSE;
  74.  
  75.     /* AXQ maps: */
  76.     CODE_SEGMENT_MAP = tup_new(0);
  77.     DATA_SEGMENT_MAP = tup_new(0);
  78.     /* Global variables */
  79.     EMAP = tup_new(0);
  80. #ifdef TBSN
  81.     PREDEF_UNITS       = [[], {}];
  82.     /* These are handled using EMAP in C version */
  83.     STATIC_DEPTH       = {
  84.     };
  85.     POSITION       = {
  86.     };
  87.     PATCHES       = {
  88.     };
  89.     EQUAL       = {
  90.     };
  91. #endif
  92.     CODE_PATCH_SET  = tup_new(0);
  93.     DATA_PATCH_SET  = tup_new(0);
  94.     PARAMETER_SET   = tup_new(0);
  95.     RELAY_SET       = tup_new(0);
  96. #ifdef TBSN
  97.     axqfiles_read   = {
  98.         '_MEMORY'    };
  99.     instruction_stack    = [];
  100.     deleted_instructions = 0;
  101.     BTIME        = 0;
  102.     optimizable_codes    = domain automat0 +/{
  103.         {x, y    }
  104. :
  105.     [x, y] in domain(automat1)+domain(automat2)};
  106. #endif
  107.     /*    Slots initialization */
  108.     /* INIT_SLOTS and MAX_INDEX are procedures in C version, defined at
  109.      * the end of this file
  110.      */
  111.     DATA_SLOTS = tup_new(0);
  112.     CODE_SLOTS = tup_new(0);
  113.     /*
  114.      * EXCEPTION_SLOTS = { ['CONSTRAINT_ERROR', 1],
  115.      *            ['NUMERIC_ERROR',    2],
  116.      *            ['PROGRAM_ERROR',    3],
  117.      *            ['STORAGE_ERROR',    4],
  118.      *            ['TASKING_ERROR',    5]
  119.      *            ['SYSTEM_ERROR',    6]
  120.      *            };
  121.      */
  122.     EXCEPTION_SLOTS = tup_new(5);
  123.     EXCEPTION_SLOTS[1] = (char *) slot_new(symbol_constraint_error, 1);
  124.     EXCEPTION_SLOTS[2] = (char *) slot_new(symbol_numeric_error, 2);
  125.     EXCEPTION_SLOTS[3] = (char *) slot_new(symbol_program_error, 3);
  126.     EXCEPTION_SLOTS[4] = (char *) slot_new(symbol_storage_error, 4);
  127.     EXCEPTION_SLOTS[5] = (char *) slot_new(symbol_tasking_error, 5);
  128.     if (!compiling_predef)  {
  129.         /* if not compiling predef, make room for predef slots */
  130.         EXCEPTION_SLOTS = tup_exp(EXCEPTION_SLOTS, 15);
  131.         init_predef_exceptions();
  132.     }
  133.  
  134.     PRECEDES_MAP = precedes_map_new();
  135.  
  136.     compilation_table = tup_new(num_predef_units);
  137.     for (i = 1; i <= num_predef_units; i++) compilation_table[i] = (char *) i;
  138.     late_instances    = tup_new(8);
  139.     late_instances[1] = strjoin("spSEQUENTIAL_IO", "");
  140.     late_instances[2] = strjoin("boSEQUENTIAL_IO", "");
  141.     late_instances[3] = strjoin("spDIRECT_IO", "");
  142.     late_instances[4] = strjoin("boDIRECT_IO", "");
  143.     late_instances[5] = strjoin("ssUNCHECKED_DEALLOCATION", "");
  144.     late_instances[6] = strjoin("suUNCHECKED_DEALLOCATION", "");
  145.     late_instances[7] = strjoin("ssUNCHECKED_CONVERSION", "");
  146.     late_instances[8] = strjoin("suUNCHECKED_CONVERSION", "");
  147.  
  148.     stubs_to_write = set_new(0);
  149.     units_in_compilation = tup_new(0);
  150.     /* integer arithmetic */
  151.     /* ADA_MIN_INTEGER and ADA_MAX_INTEGER are defined in adasem vars.c */
  152.  
  153.     /* 'standard' symbol table
  154.      * Warning : values are given for SETL only 
  155.      * IN CASE OF CHANGES IN THESE VALUES REPORT CHANGE INTO THE 
  156.      * BINDER (Initialization of idle_task data segment). 
  157.      */
  158. }
  159.  
  160. void initialize_2()                                            /*;initialize_2*/
  161. {
  162.     /*
  163.      * Initializations of file, of variables depending on the option string,
  164.      * and of variables that are to be reset between the two phases
  165.      */
  166.  
  167.     Axq    axq;
  168.     /* Variables */
  169.  
  170. #ifdef TBSL
  171.     STIME       = time;
  172. #endif
  173.     ada_line       = 0;
  174.     NB_INSTRUCTIONS = 0;
  175.     NB_STATEMENTS   = 0;
  176.  
  177.     /* tree map */
  178.  
  179.     if (!new_library) {
  180.         axq = (Axq) emalloct(sizeof(Axq_s), "axq");
  181.         load_library(axq);
  182.     }
  183. }
  184.  
  185. /* print_data_segment moved to segment.c */
  186.  
  187. /* TBSL: Note that INIT_SLOTS should be a procedure, as it is a read-only
  188.  * set
  189.  * It is referenced only by select_entry once initialized, as is the case
  190.  * also with MAX_INDEX.
  191.  */
  192. int init_slots(int kind)                                /*;init_slots*/
  193. {
  194.     int n;
  195.     if (compiling_predef) {
  196.         if (kind == SLOTS_DATA) n =  2;
  197.         else if (kind == SLOTS_CODE) n =  3;
  198.         else if (kind == SLOTS_EXCEPTION)  n = 5;
  199.         else chaos("init_slots bad kind");
  200.     }
  201.     else {
  202.         if (kind == SLOTS_DATA)
  203.         n = 8;
  204.         else if (kind == SLOTS_CODE)
  205.         n = 11;
  206.         else if (kind == SLOTS_EXCEPTION)  n =  15;
  207.         else chaos("init_slots bad kind");
  208.     }
  209.     return n;
  210. }
  211.  
  212. int max_index(int kind)                                            /*;max_index*/
  213. {
  214.     if (kind == SLOTS_DATA) return 255;
  215.     else if (kind == SLOTS_CODE) return 32767;
  216.     else if (kind == SLOTS_EXCEPTION) return 255;
  217.     chaos("max_slots bad kind");
  218.     return 0;
  219. }
  220.  
  221. static Tuple precedes_map_new()                            /*;precedes_map_new*/
  222. {
  223.     return (tup_new(0));
  224. }
  225.  
  226. Slot slot_new(Symbol sym, int number)                            /*;slot_new*/
  227. {
  228.     Slot s;
  229.     char    *sname;
  230.  
  231.     s = (Slot) emalloct(sizeof(Slot_s), "slot-new");
  232.     s->slot_seq = S_SEQ(sym);
  233.     s->slot_unit = S_UNIT(sym);
  234.     sname = ORIG_NAME(sym);
  235.     /* Make copy */
  236.     s->slot_name = (sname == (char *)0) ? (char *)0 : strjoin(sname, "");
  237.  
  238. #ifdef MONITOR
  239. #define NAMESIZE 119
  240.     {
  241.     static FILE *fp = NULL;
  242.     static char source_file[NAMESIZE], *s_file;
  243.     static char *MAIN = "main";
  244.     char *package_name;
  245.     static int length;
  246.  
  247.     /***************************************************/
  248.     /*  Save the file for this procedure.              */
  249.     /***************************************************/
  250.  
  251.     if ( fp == NULL )
  252.     {
  253.         fp = fopen( "CWKLIB.$$$", "r" );
  254.         if ( fp == NULL )
  255.         {
  256.             fprintf(stderr, "Cannot open CWKLIB\n");
  257.         }
  258.         fgets( source_file, NAMESIZE, fp );
  259.         length = strlen(source_file);
  260.         source_file[length-1] = '\0';
  261.         s_file = malloc(length * sizeof(char) );
  262.         strncpy( s_file, source_file, length );
  263.     }
  264.     s->slot_file = s_file;
  265.  
  266.     /***************************************************/
  267.     /*  Save the package name for this procedure.      */
  268.     /***************************************************/
  269.  
  270.     if ( *MON_PACKAGE_NAME == '\0' )
  271.     {
  272.         s->slot_package = MAIN;
  273.     }
  274.     else
  275.     {
  276.         length = strlen( MON_PACKAGE_NAME );
  277.         package_name = malloc( (length+1) * sizeof(char) );
  278.         strcpy( package_name, MON_PACKAGE_NAME );
  279.         s->slot_package = package_name;
  280.     }
  281.     }
  282. #undef NAMESIZE
  283. #endif
  284.  
  285.     s->slot_number = number;
  286.     return s;
  287. }
  288.  
  289. static void init_predef_exceptions()                /*;init_predef_exceptions*/
  290. {
  291.     /* the body of this procedure is obtained by examining the standard
  292.      * output when compiling predef!  Hopefully a more rational scheme
  293.      * of initialization will be provided in the future (after validation).
  294.      *    shields  11-5-85
  295.      */
  296.  
  297.     init_predef_exception(26, 1, 6, "SYSTEM_ERROR");
  298.     init_predef_exception(3, 2, 7, "STATUS_ERROR");
  299.     init_predef_exception(4, 2, 8, "MODE_ERROR");
  300.     init_predef_exception(5, 2, 9, "NAME_ERROR");
  301.     init_predef_exception(6, 2, 10, "USE_ERROR");
  302.     init_predef_exc